home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha Extra 2004 January / CyberMycha Extra 1-2004 (Poland) (Disc 2).bin / Pippi / common.cst / 00005_sessionObjectScript.ls < prev    next >
Encoding:
Text File  |  2001-09-04  |  8.2 KB  |  291 lines

  1. global gmObject, sndObject, monkey --gameobjektet, ers├ñtts vid varje nytt spel, soundObject
  2.  
  3. global fileIoTxt --kolla om denna verkligen beh├╢vs f├╢r att f├╢da fileIo!!!!
  4.  
  5. property beenTo --lista p├Ñ vilka spel man har varit i redan
  6. property buttonSpritesUpper, vPosButtonUpper --knapparna i ├╢vre raden
  7. property city
  8. property nextMovie
  9. property cdVirgin --om det ├ñr f├╢rsta g├Ñngen, triggar hj├ñlpen i oh automatiskt
  10. property introSoundTrig --triggas av ingm n├ñr man ska g├Ñ till ett spel
  11. ------------------------------------------------------------------------------------------------------------------------------
  12.  
  13. property osDrive, cdPath, txtFile, deskTopPath, del, myColor --propertys f├╢r att h├Ñlla r├ñtt p├Ñ s├╢kv├ñgar och s├Ñnt s
  14. ------------------------------------------------------------------------------------------------------------------------------
  15.  
  16. on new me
  17.   -----fileStuff
  18.   register xtra "PrintOMatic","PMAT162-616-46606"
  19.   cdPath = the moviePath
  20.   deskTopPath = 0
  21.   
  22.   findOsDrive me
  23.   findDesktop me
  24.   findTxtFile me
  25.   writeCdPath me
  26.   
  27.   -----knappar
  28.   buttonSpritesUpper = [133, 143] --├╢vre knappradens spriteNummer h├ÑrdK├Ñd
  29.   vPosButtonUpper = 300 -- position(v) om knappen ska synas, h├ÑrdK├Ñd
  30.   introSoundTrig = 0
  31.   
  32.   return me
  33. end
  34.  
  35. ------------------------------------------------------------------------------------------------------------------------------
  36. --kolla mot text-fil p├Ñ disk, skriva till disk/autospar
  37. ------------------------------------------------------------------------------------------------------------------------------
  38. on saveCity me
  39.   city = 1
  40.   autoSaveBeenTo me
  41. end
  42.  
  43. on getBeenTo me, whatColor --kopplar mot txt-fil p├Ñ hd n├ñr man v├ñljer en f├ñrg
  44.   myColor = symbol(whatColor)
  45.   fileIoTxt = new(xtra "fileio")
  46.   openFile(fileIoTxt, txtFile, 1)
  47.   txt = value(readFile(fileIoTxt))
  48.   beenTo = txt[myColor]
  49.   city = value(txt[#city][myColor])
  50.   closeFile fileIoTxt
  51.   fileIoTxt = 0
  52. end
  53.  
  54. on autoSaveBeenTo me
  55.   fileIoTxt = new(xtra "fileio")
  56.   openFile(fileIoTxt, txtFile, 0)
  57.   txt = value(readFile(fileIoTxt))
  58.   delete(fileIoTxt)
  59.   closeFile(fileIoTxt)
  60.   createFile(fileIoTxt, txtFile)
  61.   openFile(fileIoTxt, txtFile, 0)
  62.   txt[myColor] = beenTo
  63.   txt[#city][myColor] = city
  64.   writeString(fileIoTxt, string(txt))
  65.   closeFile(fileIoTxt)
  66.   fileIoTxt = 0
  67. end
  68.  
  69. ------------------------------------------------------------------------------------------------------------------------------
  70.  
  71. on findOsDrive me
  72.   v = getOSDirectory()
  73.   num = v.chars.count
  74.   
  75.   if (the platform).char[1..3] = "Win" then
  76.     del = "\"
  77.   else
  78.     del = ":"
  79.   end if
  80.   
  81.   repeat with n = 1 to num
  82.     if v.char[n] = del then
  83.       osDrive = v.char[1..n]
  84.       exit repeat
  85.     end if
  86.   end repeat
  87. end
  88.  
  89. on findDesktop me
  90.   buddy = new(xtra "budapi")
  91.   deskTopPath = baSysFolder("desktop")
  92.   buddy = 0
  93. end
  94.  
  95. on findTxtFile me
  96.   txtFile = osDrive&"pippilst.txt"
  97.   if FileExists(txtFile) <> 0 then
  98.     cdVirgin = 1
  99.     installPippi me
  100.   else
  101.     cdVirgin = 0
  102.     checkTxtFile me
  103.   end if
  104.   
  105. end
  106.  
  107. on checkTxtFile me
  108.   corrupt = 0
  109.   
  110.   fileIoTxt = new(xtra "fileio")
  111.   openFile(fileIoTxt, txtFile, 1)
  112.   txt = value(readFile(fileIoTxt))
  113.   
  114.   if listP(txt) = 0 then
  115.     corrupt = 1
  116.     put "corrupt: not a list"
  117.   end if
  118.   if corrupt = 0 then
  119.     if txt.count <> 6 then
  120.       corrupt = 1
  121.       put "corrupt: wrong number of items in list"
  122.     end if
  123.   end if
  124.   if corrupt = 0 then
  125.     repeat with n = 1 to 6
  126.       if voidP(txt[n]) = 1 then
  127.         corrupt = 1
  128.         put "corrupt: void item in list"
  129.         exit repeat
  130.       end if
  131.     end repeat
  132.   end if
  133.   
  134.   if corrupt = 1 then
  135.     deleteCorruptFile me
  136.     installPippi me
  137.   end if
  138. end
  139.  
  140. on deleteCorruptFile me
  141.   DeleteFile(txtFile)
  142. end
  143.  
  144. on installPippi me
  145.   if del = ":" then
  146.     suffix = ""
  147.   else
  148.     suffix = ".exe"
  149.   end if
  150.   
  151.   --g├╢ra en helt ny fil och fylla med tomma listan
  152.   
  153.   fileIoTxt = new(xtra "fileio")
  154.   emptyListFile = osDrive&"pippilst.txt"
  155.   txt = [#cdDrive:"empty", #city: [#red: 0, #blue: 0, #green: 0, #yellow: 0], #red:[[]], #blue:[[]], #green:[[]], #yellow:[[]]]
  156.   createFile(fileIoTxt, emptyListFile)
  157.   openFile(fileIoTxt, emptyListFile, 0)
  158.   writeString(fileIoTxt, string(txt))
  159.   closeFile fileIoTxt
  160.   fileIoTxt = 0
  161.   
  162.   --slut: g├╢ra en helt ny fil och fylla med tomma listan
  163.   if deskTopPath <> 0 then
  164.     CopyFile cdPath&"toDesk"&del&"Pippi"&suffix, deskTopPath&"Pippi"&suffix
  165.   end if
  166.   
  167. end
  168.  
  169. on writeCdPath me
  170.   fileIoTxt = new(xtra "fileio")
  171.   openFile(fileIoTxt, txtFile, 0)
  172.   txt = value(readFile(fileIoTxt))
  173.   delete(fileIoTxt)
  174.   closeFile(fileIoTxt)
  175.   createFile(fileIoTxt, txtFile)
  176.   openFile(fileIoTxt, txtFile, 0)
  177.   txt[#cdDrive] = cdPath
  178.   writeString(fileIoTxt, string(txt))
  179.   closeFile(fileIoTxt)
  180.   fileIoTxt = 0
  181. end
  182.  
  183. ------------------------------------------------------------------------------------------------------------------------------
  184. ------------------------------------------------------------------------------------------------------------------------------
  185.  
  186. --anropas fr├Ñn knapparna f├╢r att g├Ñ till r├ñtt frame i spel-filmerna
  187. on getFrame me, pMovie
  188.   if pMovie = "is" or pMovie = "sl" then
  189.     xFrame = random(4)
  190.   else
  191.     xFrame = 1
  192.   end if
  193.   
  194.   repeat with b = 2 to (beenTo.count)
  195.     if  beenTo[b][1] = pMovie then
  196.       xFrame = beenTo[b][2]
  197.       exit repeat
  198.     end if
  199.   end repeat
  200.   return xFrame
  201. end
  202.  
  203. ------------------------------------------------------------------------------------------------------------------------------
  204. --initiering och avslutning av olika sorts filmer
  205. ------------------------------------------------------------------------------------------------------------------------------
  206.  
  207. on initGmMovie me --alla game-filer initieras med denna
  208.   --kolla om anv├ñndaren har varit h├ñr f├╢rut annars l├ñgga till spelet till listan som g├╢r att en knapp finns i ├╢vre listen
  209.   writeGm = 1
  210.   repeat with n = 2 to beenTo.count
  211.     if (the moviename).char[3..4] = beenTo[n][1] then
  212.       writeGm = 0
  213.       exit repeat
  214.     end if
  215.   end repeat
  216.   if writeGm = 1 then --ifall det ├ñr f├╢rsta g├Ñngen p├Ñ detta spel s├Ñ..
  217.     beenTo[(beenTo.count) + 1] = [((the moviename).char[3..4]), 1] --spara till listan beenTo... sista v├ñrdet betyder frame 1 i filmen
  218.     autoSaveBeenTo me --samt spara till disk
  219.   end if
  220.   adjustButtons me --ordna knapparna i ├╢vre listen
  221.   if the number of castlibs = 3 then --ifall det finns responsSounds som ska l├ñsas in i soundObjectet
  222.     sndObject.initRespondlist()
  223.   end if
  224.   
  225.   if introSoundTrig = 1 then
  226.     sound(2).play(member("introSnd", 1)) --f├╢rklaringsSpeaker
  227.   end if
  228.   introSoundTrig = 0
  229. end
  230.  
  231. on upCountGmMovie me, frameValue --ifall man ska till en annan frame i filmen n├ñsta g├Ñng man kommer dit
  232.   repeat with b = 2 to (beenTo.count)
  233.     if  beenTo[b][1] = (the moviename).char[3..4] then
  234.       beenTo[b][2] = frameValue
  235.       exit repeat
  236.     end if
  237.   end repeat
  238.   autoSaveBeenTo me --spara till disk
  239. end
  240.  
  241. on finitGmMovie me, frameValue --alla gameFiler avslutas med denna
  242.   gmObject = 0 --d├╢da spelObjektet
  243. end
  244.  
  245. on initMyMovie me --alla meny-filer initieras
  246.   adjustButtons me --ordna knapparna i ├╢vre listen
  247. end
  248.  
  249. on initIntroMovie me, pNextMovie --alla meny-filer initieras
  250.   set the keyDownScript to "sessionObject.keyHit()"
  251.   nextMovie = pNextMovie
  252. end
  253.  
  254. on finitIntroMovie me
  255.   set the keyDownScript to ""
  256. end
  257.  
  258. on keyHit me
  259.   if the keyCode = 49 then
  260.     if objectP(monkey) = 0 then
  261.       monkey = new(script "monkeyScript")
  262.     end if
  263.     sound(2).stop()
  264.     set the keyDownScript to ""
  265.     go movie nextMovie
  266.   end if
  267. end
  268.  
  269. on adjustButtons me --ordna knapparna
  270.   sound(1).volume = 150
  271.   sprite(150).initMe() --s├ñtta apan r├ñtt
  272.   if city = 1 then
  273.     sprite(148).locV = vPosButtonUpper
  274.   end if
  275.   if beenTo.count > 1 then
  276.     repeat with b = 2 to (beenTo.count)
  277.       repeat with n = buttonSpritesUpper[1] to buttonSpritesUpper[2]
  278.         if sprite(n).member.name = beenTo[b][1] then
  279.           sprite(n).locV = vPosButtonUpper
  280.           exit repeat
  281.         end if
  282.       end repeat
  283.     end repeat
  284.   end if
  285. end
  286.  
  287. ------------------------------------------------------------------------------------------------------------------------------
  288. ------------------------------------------------------------------------------------------------------------------------------
  289. ------------------------------------------------------------------------------------------------------------------------------
  290.  
  291.